#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;

const int maxn = 100001;
const double eps = 0.05;
double ep1[maxn], ep2[maxn], ep3[maxn];

int main()
{
	memset(ep1, 0, sizeof(ep1));
	memset(ep2, 0, sizeof(ep2));
	memset(ep3, 0, sizeof(ep3));
	int max1 = 0, max2 = 0;
	int n, m; int a; double b;
	cin >> n;
	for (int i = 0; i < n; i++)
	{

		scanf("%d %lf", &a, &b);
		ep1[a] = b;
		if (a > max1)  max1 = a;
	}
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %lf", &a, &b);
		ep2[a] = b;
		if (a > max2)  max2 = a;
	}
	if (max1 < max2)
	{
		printf("0 0 0.0\n");
		printf("%d", n);
		for (int i = max1; i >= 0; i--)
		{
			if (fabs(ep1[i]) >= eps)
				printf(" %d %.1lf", i, ep1[i]);
		}
	}
	else
	{
		int t = max1;
		while (max1 >= max2)
		{
			double y = ep1[max1] / ep2[max2];
			ep3[max1 - max2] = y;
			for (int i = max2; i >= 0; i--)
			{
				if (fabs(ep2[i]) >= eps)
					ep1[max1 + i - max2] -= y * ep2[i];
			}
			int pos = 0;
			for (int i = max1; i >= 0; i--)
			{
				if (fabs(ep1[i]) >= eps)
				{
					pos = i;
					break;
				}
			}
			max1 = pos;
		}
		int n1 = 0, n2 = 0;
		for (int i = t; i >= 0; i--)
			if (fabs(ep1[i]) >= eps)
				n1++;
		for (int i = t; i >= 0; i--)
			if (fabs(ep3[i]) >= eps)
				n2++;
		if (n2 == 0)
		{
			printf("0 0 0.0\n");
		}
		else
		{
			printf("%d", n2);
			for (int i = t; i >= 0; i--)
				if (fabs(ep3[i]) >= eps)
					printf(" %d %.1lf", i, ep3[i]);
			cout << endl;
		}
		if (n1 == 0)
		{
			printf("0 0 0.0\n");
		}
		else
		{
			printf("%d", n1);
			for (int i = t; i >= 0; i--)
				if (fabs(ep1[i]) >= eps)
					printf(" %d %.1lf", i, ep1[i]);
		}
	}
}
